<template>
    <div style="padding: 8px;">
        <el-card>
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
                <el-form-item label="订单编号">
                    <el-input size="small" v-model="formInline.recordId" placeholder="订单编号"></el-input>
                </el-form-item>
                <el-form-item label="用户邮箱">
                    <el-input size="small" v-model="formInline.email" placeholder="用户邮箱"></el-input>
                </el-form-item>
                <el-form-item label="用户手机">
                    <el-input size="small" v-model="formInline.phone" placeholder="用户手机"></el-input>
                </el-form-item>
                <!-- <el-form-item :label="$t('创建时间')">
            <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="formInline.createTime" size="small" type="datetime"
              :placeholder="$t('选择日期时间')">
            </el-date-picker>
          </el-form-item> -->
                <el-form-item>
                    <el-button size="small" type="primary" @click="onSubmit">查询</el-button>
                    <el-button size="small" type="primary" @click="reSet">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card v-loading="loading" style="margin-top: 8px;">
            <el-table :data="tableData" style="width: 100%">
                <el-table-column prop="recordId" label="订单编号">
                </el-table-column>
                <el-table-column prop="phone" label="用户手机">
                </el-table-column>
                <el-table-column prop="email" label="用户邮箱">
                </el-table-column>
                <!-- <el-table-column prop="urlCFP" label="CFP地址">
                </el-table-column> -->
                <el-table-column prop="balanceCfp" label="CFP余额">
                </el-table-column>
                <el-table-column prop="balanceUsdt" label="USDT余额">
                </el-table-column>
                <el-table-column prop="usdtAddress" label="USDT提现地址">
                </el-table-column>
                <el-table-column prop="amount" label="提现USDT数量">
                    <template #default="{ row }">
                        <span>{{ row.amount - 2 }}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="usdtAddressType" label="USDT地址类型">
                </el-table-column>
                <el-table-column prop="createTime" label="提现发起时间">
                </el-table-column>
                <el-table-column prop="createTime" label="操作">
                    <template #default="{ row }">
                        <el-button @click="approve(row)" type="text" size="mini">审批</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination style="float: right;margin: 5px 0;" @size-change="handleSizeChange"
                @current-change="handleCurrentChange" layout="total, prev, pager, next" :total="total">
            </el-pagination>
        </el-card>
        <el-dialog title="审批" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
            <el-descriptions :column="1">
                <el-descriptions-item label="提现订单编号">{{ form.recordId }}</el-descriptions-item>
                <el-descriptions-item label="订单时间">{{ form.createTime }}</el-descriptions-item>
                <el-descriptions-item label="手机">{{ form.phone }}</el-descriptions-item>
                <el-descriptions-item label="邮箱">{{ form.email }}</el-descriptions-item>
                <el-descriptions-item label="CFP余额">{{ form.balanceCfp }}</el-descriptions-item>
                <el-descriptions-item label="USDT余额">{{ form.balanceUsdt }}</el-descriptions-item>
                <el-descriptions-item label="USDT提现地址">{{ form.usdtAddress }}
                    <el-button @click="copy(form.usdtAddress)" size="small" style="margin-left: 10px;"
                        type="primary">复制</el-button>
                </el-descriptions-item>
                <el-descriptions-item label="USDT地址类型">{{ form.usdtAddressType }}</el-descriptions-item>
                <el-descriptions-item label="提现数量(已扣除2USDT手续费)">{{ form.amount - 2 }}</el-descriptions-item>
                <el-descriptions-item label="备注">
                    <el-input v-model="form.remarks" type="textarea" :rows="2" placeholder="请输入备注信息"></el-input>
                </el-descriptions-item>
            </el-descriptions>
            <div style="display: flex;justify-content: end;">
                <el-button type="danger" @click="cancel">拒绝</el-button>
                <el-button type="primary" @click="save">通过</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import { getWithdrawalApprovalListApi, getWithdrawalApprovalEditApi } from "@/api/appuser/WithdrawalApproval.js";
export default {
    data() {
        return {
            loading: false,
            tableData: [{}],
            formInline: {
                recordId: null,
                email: null,
                phone: null,
            },
            total: 0,
            page: {
                pageNum: 1,
                pageSize: 10,
            },
            dialogVisible: false,
            form: {
                recordId: null,
                createTime: null,
                phone: null,
                email: null,
                balanceCfp: null,
                balanceUsdt: null,
                usdtAddress: null,
                amount: null,
                usdtAddressType: null,
                remarks: null,
            }
        };
    },
    created() {
        this.getWithdrawalApprovalList()
    },
    methods: {
        onSubmit() {
            this.page = {
                pageNum: 1,
                pageSize: 10,
            }
            this.getWithdrawalApprovalList()
        },
        async getWithdrawalApprovalList() {
            this.loading = true
            const res = await getWithdrawalApprovalListApi({
                ...this.page,
                ...this.formInline
            })
            console.log(res);
            this.tableData = res.list
            this.total = res.total
            this.loading = false
        },
        reSet() {
            this.page = {
                pageNum: 1,
                pageSize: 10,
            }
            this.formInline = {
                recordId: null,
                email: null,
                phone: null,
            }
            this.getWithdrawalApprovalList()
        },
        handleSizeChange(val) {
            this.page.pageSize = val;
            this.getWithdrawalApprovalList();
        },
        handleCurrentChange(val) {
            this.page.pageNum = val;
            this.getWithdrawalApprovalList();
        },
        approve(row) {
            this.form = row
            this.dialogVisible = true
        },
        handleClose() {
            this.dialogVisible = false
            this.form = {
                recordId: null,
                createTime: null,
                phone: null,
                email: null,
                balanceCfp: null,
                balanceUsdt: null,
                usdtAddress: null,
                amount: null,
                usdtAddressType: null,
                remarks: null,
            }
        },
        save() {
            this.$confirm('确定要通过吗？').then(async () => {
                console.log(this.form);
                await getWithdrawalApprovalEditApi({
                    id: this.form.id,
                    orderStatus: 1,
                    remarks: this.form.remarks
                })
                this.$message({
                    type: 'success',
                    message: '通过成功!'
                });
                this.handleClose()
                this.getWithdrawalApprovalList()
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });
            });

        },
        cancel() {
            if (!this.form.remarks) {
                return this.$message({
                    type: 'warning',
                    message: '请填写拒绝原因!'
                });
            }
            this.$confirm('确定要拒绝吗？').then(async () => {
                await getWithdrawalApprovalEditApi({
                    id: this.form.id,
                    orderStatus: 2,
                    remarks: this.form.remarks
                })
                this.$message({
                    type: 'success',
                    message: '拒绝成功!'
                });
                this.handleClose()
                this.getWithdrawalApprovalList()
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });
            });
        },
        copy(text) {
            var input = document.createElement('textarea');
            input.value = text;
            document.body.appendChild(input);
            input.select();
            document.execCommand('copy');
            document.body.removeChild(input);
            this.$message({
                type: 'success',
                message: '复制成功'
            });
        }
    },
};
</script>
<style lang='' scoped>
</style>